<!doctype html>
<html lang="zh"><head>
<title>java-封装一个向github仓库上传文件的工具 - 糖羽仙</title>
<meta charset="UTF-8">
<meta name="keywords" content="blog ACG JavaScript VUE IT">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">

<link rel="shortcut icon" href="/images/head/head.jpg" type="image/jpeg" />
<meta name="description" content="在网上没有找到java版的向github仓库上传文件的工具,于是便自己查api封装一个">
<meta property="og:type" content="article">
<meta property="og:title" content="java-封装一个向github仓库上传文件的工具">
<meta property="og:url" content="https://www.tangyuxian.com/2022/07/10/%E5%90%8E%E7%AB%AF/java/java-%E5%B0%81%E8%A3%85%E4%B8%80%E4%B8%AA%E5%90%91github%E4%BB%93%E5%BA%93%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6%E7%9A%84%E5%B7%A5%E5%85%B7/index.html">
<meta property="og:site_name" content="糖羽仙">
<meta property="og:description" content="在网上没有找到java版的向github仓库上传文件的工具,于是便自己查api封装一个">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.tangyuxian.com/PicGoImages/202211102009917.png">
<meta property="og:image" content="https://cdn.tangyuxian.com/PicGoImages/202211102015899.png">
<meta property="og:image" content="https://cdn.tangyuxian.com/PicGoImages/202211102018060.png">
<meta property="og:image" content="https://cdn.tangyuxian.com/PicGoImages/202211102034626.png">
<meta property="og:image" content="https://img1.baidu.com/it/u=4140348184,4234695059&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400">
<meta property="article:published_time" content="2022-07-10T11:52:44.000Z">
<meta property="article:modified_time" content="2022-11-29T05:34:22.780Z">
<meta property="article:author" content="tangyuxian">
<meta property="article:tag" content="java">
<meta property="article:tag" content="github">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.tangyuxian.com/PicGoImages/202211102009917.png">

<link rel="stylesheet" href="/lib/fancybox/fancybox.css">
<link rel="stylesheet" href="/lib/mdui_043tiny/mdui.css">


<link rel="stylesheet" href="/lib/iconfont/iconfont.css?v=1763992124067">

    <link rel="stylesheet" href="//at.alicdn.com/t/font_2421060_8z08qcz5sq3.css">

<link rel="stylesheet" href="/css/style.css?v=1763992124067">




    
        <link rel="stylesheet" href="/custom.css?v=1763992124067">
    
        <link rel="stylesheet" href="/themes/umaru/index.css?v=1763992124067">
    
        <link rel="stylesheet" href="/themes/asuka/index.css?v=1763992124067">
    



<script src="/lib/mdui_043tiny/mdui.js" async></script>
<script src="/lib/fancybox/fancybox.umd.js" async></script>
<script src="/lib/lax.min.js" async></script>


<script async src="/js/app.js?v=1763992124067"></script>

 

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-1Z7TFL96ZH"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-1Z7TFL96ZH');
</script>


<link rel="stylesheet"  href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/atom-one-dark.min.css">
<!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-shiki-plugin@latest/lib/codeblock.css">
<style>:root{--hl-color:#e1e4e8;--hl-bg:#24292e;--hltools-bg:#1f2428;--hltools-color:#c5c5c5;--hlnumber-bg:#24292e;--hlnumber-color:#444d56;--hlscrollbar-bg:#32383e;--hlexpand-bg:linear-gradient(180deg,rgba(36,41,46,0.1),rgba(36,41,46,0.9))}</style><!-- hexo injector head_end end --><meta name="generator" content="Hexo 7.3.0"></head><body class="nexmoe mdui-drawer-body-left"><div id="nexmoe-background"><div class="nexmoe-bg" style="background-image: url(/images/background/xiaomai.jpg)"></div><div class="nexmoe-character"></div><div class="mdui-appbar mdui-shadow-0"><div class="mdui-toolbar"><a class="mdui-btn mdui-btn-icon mdui-ripple" mdui-drawer="{target: &#039;#drawer&#039;, swipe: true}" title="menu"><i class="mdui-icon nexmoefont icon-menu"></i></a><div class="mdui-toolbar-spacer"></div><a class="mdui-btn mdui-btn-icon" href="/" title="tangyuxian"><img src="/images/head/head.jpg" alt="tangyuxian"></a></div></div></div><div id="nexmoe-header"><div class="nexmoe-drawer mdui-drawer" id="drawer">
    <div class="nexmoe-avatar mdui-ripple">
        <a href="/" title="tangyuxian">
            <img src="/images/head/head.jpg" alt="tangyuxian" alt="tangyuxian">
        </a>
    </div>
    <div class="nexmoe-count">
        <div class="nexmoe-count-item"><span>文章</span>84 <div class="item-radius"></div><div class="item-radius item-right"></div> </div>
        <div class="nexmoe-count-item"><span>标签</span>38<div class="item-radius"></div><div class="item-radius item-right"></div></div>
        <div class="nexmoe-count-item"><span>分类</span>5<div class="item-radius"></div><div class="item-radius item-right"></div></div>
    </div>
    <div class="nexmoe-list mdui-list" mdui-collapse="{accordion: true}">
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple false" href="/" title="回到首页">
            <i class="mdui-list-item-icon nexmoefont icon-meishi"></i>
            <div class="mdui-list-item-content">
                回到首页
            </div>
        </a>
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple false" href="/archives.html" title="文章归档">
            <i class="mdui-list-item-icon nexmoefont icon-hanbao1"></i>
            <div class="mdui-list-item-content">
                文章归档
            </div>
        </a>
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple false" href="/about.html" title="关于糖糖">
            <i class="mdui-list-item-icon nexmoefont icon-jiubei1"></i>
            <div class="mdui-list-item-content">
                关于糖糖
            </div>
        </a>
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple false" href="/friend.html" title="我的朋友">
            <i class="mdui-list-item-icon nexmoefont icon-cola"></i>
            <div class="mdui-list-item-content">
                我的朋友
            </div>
        </a>
        
    </div>
    
    
        
        <div class="nexmoe-widget-wrap">
    <div class="nexmoe-widget nexmoe-search">
         
            <form id="search_form" action_e="https://cn.bing.com/search?q=site:tangyuxian.com" onsubmit="return search();">
                <label><input id="search_value" name="q" type="search" placeholder="搜索"></label>
            </form>
         
    </div>
</div>




    
        
        <div class="nexmoe-widget-wrap">
	<div class="nexmoe-widget nexmoe-social">
		<a
			class="mdui-ripple"
			href="http://wpa.qq.com/msgrd?v=3&uin=2120252100&site=qq&menu=yes"
			target="_blank"
			mdui-tooltip="{content: 'QQ'}"
			style="
				color: rgb(64, 196, 255);
				background-color: rgba(64, 196, 255, .1);
			"
		>
			<i
				class="nexmoefont icon-QQ"
			></i> </a
		><a
			class="mdui-ripple"
			href="mailto:tangyuxian@vip.qq.com"
			target="_blank"
			mdui-tooltip="{content: 'mail'}"
			style="
				color: rgb(249,8,8);
				background-color: rgba(249,8,8,.1);
			"
		>
			<i
				class="nexmoefont icon-mail-fill"
			></i> </a
		><a
			class="mdui-ripple"
			href="https://blog.csdn.net/qq_40621378?type=blog"
			target="_blank"
			mdui-tooltip="{content: 'CSDN'}"
			style="
				color: rgb(199,29,35);
				background-color: rgba(199,29,35,.1);
			"
		>
			<i
				class="nexmoefont icon-csdn"
			></i> </a
		><a
			class="mdui-ripple"
			href="https://www.cnblogs.com/lovetangyuxian/"
			target="_blank"
			mdui-tooltip="{content: '博客园'}"
			style="
				color: rgb(66, 214, 29);
				background-color: rgba(66, 214, 29, .1);
			"
		>
			<i
				class="nexmoefont icon-bokeyuan"
			></i> </a
		><a
			class="mdui-ripple"
			href="https://github.com/tangyuxian/"
			target="_blank"
			mdui-tooltip="{content: 'GitHub'}"
			style="
				color: rgb(25, 23, 23);
				background-color: rgba(25, 23, 23, .15);
			"
		>
			<i
				class="nexmoefont icon-github"
			></i> </a
		><a
			class="mdui-ripple"
			href="https://gitee.com/tangyuxian"
			target="_blank"
			mdui-tooltip="{content: 'gitee'}"
			style="
				color: rgb(255, 255, 255);
				background-color: rgb(199,29,35);
			"
		>
			<i
				class="nexmoefont icon-mayun"
			></i> </a
		>
	</div>
</div>

    
        
        
  <div class="nexmoe-widget-wrap">
    <h3 class="nexmoe-widget-title">文章分类</h3>
    <div class="nexmoe-widget">

      <ul class="category-list">

        


        

        

        <li class="category-list-item">
          <a class="category-list-link" href="/categories/其它/">其它</a>
          <span class="category-list-count">2</span>
        </li>

        

        <li class="category-list-item">
          <a class="category-list-link" href="/categories/前端/">前端</a>
          <span class="category-list-count">62</span>
        </li>

        

        <li class="category-list-item">
          <a class="category-list-link" href="/categories/后端/">后端</a>
          <span class="category-list-count">8</span>
        </li>

        

        <li class="category-list-item">
          <a class="category-list-link" href="/categories/开发工具/">开发工具</a>
          <span class="category-list-count">11</span>
        </li>

        

        <li class="category-list-item">
          <a class="category-list-link" href="/categories/服务器端/">服务器端</a>
          <span class="category-list-count">1</span>
        </li>

        
      </ul>

    </div>
  </div>


    
        
        
  <div class="nexmoe-widget-wrap">
    <div id="randomtagcloud" class="nexmoe-widget tagcloud nexmoe-rainbow">
      <a href="/tags/JavaScript/" style="font-size: 15.56px;">JavaScript</a> <a href="/tags/Jetbrains/" style="font-size: 10px;">Jetbrains</a> <a href="/tags/TypeScript/" style="font-size: 10px;">TypeScript</a> <a href="/tags/UI%E5%BA%93/" style="font-size: 13.33px;">UI库</a> <a href="/tags/centos/" style="font-size: 10px;">centos</a> <a href="/tags/css/" style="font-size: 11.11px;">css</a> <a href="/tags/docker/" style="font-size: 10px;">docker</a> <a href="/tags/echarts/" style="font-size: 10px;">echarts</a> <a href="/tags/elementPlus/" style="font-size: 13.33px;">elementPlus</a> <a href="/tags/es6/" style="font-size: 14.44px;">es6</a> <a href="/tags/git/" style="font-size: 13.33px;">git</a> <a href="/tags/github/" style="font-size: 10px;">github</a> <a href="/tags/html/" style="font-size: 10px;">html</a> <a href="/tags/http/" style="font-size: 13.33px;">http</a> <a href="/tags/java/" style="font-size: 11.11px;">java</a> <a href="/tags/markerdown/" style="font-size: 11.11px;">markerdown</a> <a href="/tags/nginx/" style="font-size: 10px;">nginx</a> <a href="/tags/node/" style="font-size: 13.33px;">node</a> <a href="/tags/vite/" style="font-size: 10px;">vite</a> <a href="/tags/vue/" style="font-size: 18.89px;">vue</a> <a href="/tags/webpack/" style="font-size: 10px;">webpack</a> <a href="/tags/xuex/" style="font-size: 10px;">xuex</a> <a href="/tags/%E4%BA%8B%E4%BB%B6%E6%B5%81/" style="font-size: 10px;">事件流</a> <a href="/tags/%E4%BA%92%E8%81%94%E7%BD%91/" style="font-size: 10px;">互联网</a> <a href="/tags/%E5%8A%A0%E5%AF%86/" style="font-size: 12.22px;">加密</a> <a href="/tags/%E5%8E%9F%E5%88%9B/" style="font-size: 20px;">原创</a> <a href="/tags/%E5%B7%A5%E5%85%B7/" style="font-size: 13.33px;">工具</a> <a href="/tags/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/" style="font-size: 12.22px;">微信小程序</a> <a href="/tags/%E6%80%BB%E7%BB%93/" style="font-size: 13.33px;">总结</a> <a href="/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" style="font-size: 10px;">数据结构</a> <a href="/tags/%E6%9C%8D%E5%8A%A1%E5%99%A8/" style="font-size: 10px;">服务器</a> <a href="/tags/%E6%B5%8F%E8%A7%88%E5%99%A8/" style="font-size: 17.78px;">浏览器</a> <a href="/tags/%E7%AE%97%E6%B3%95/" style="font-size: 14.44px;">算法</a> <a href="/tags/%E7%BC%96%E8%A7%A3%E7%A0%81/" style="font-size: 10px;">编解码</a> <a href="/tags/%E7%BE%8E%E5%8C%96/" style="font-size: 12.22px;">美化</a> <a href="/tags/%E8%A7%86%E9%A2%91/" style="font-size: 11.11px;">视频</a> <a href="/tags/%E8%AE%B0%E5%BD%95/" style="font-size: 11.11px;">记录</a> <a href="/tags/%E8%BD%AC%E8%BD%BD/" style="font-size: 16.67px;">转载</a>
    </div>
    
      <script>
        var maxTagcloud = parseInt(17);
        var tags_length = parseInt(38);
        var tags_arr = [];
        for(var i = 0; i < tags_length; i++){
          tags_arr.push(i);
        }
        tags_arr.sort(function (l, r) {
          return Math.random() > 0.5 ? -1 : 1;
        });
        tags_arr = tags_arr.slice(0, maxTagcloud < tags_length ? tags_length - maxTagcloud : 0);
        for(var tag_i = 0; tag_i < tags_arr.length; tag_i++){
          document.getElementById("randomtagcloud").children[tags_arr[tag_i]].style.display = 'none';
        }
      </script>
    
  </div>

    
        
        
        
  <div class="nexmoe-widget-wrap">
    <h3 class="nexmoe-widget-title">文章归档</h3>
    <div class="nexmoe-widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2025/">2025</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2023/">2023</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/">2022</a><span class="archive-list-count">23</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/">2021</a><span class="archive-list-count">54</span></li></ul>
    </div>
  </div>



    
        
        
  <div class="nexmoe-widget-wrap">
    <h3 class="nexmoe-widget-title">最新文章</h3>
    <div class="nexmoe-widget">
      <ul>
        
          <li>
            <a href="/2025/11/12/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/%E7%BE%8E%E5%8C%96/%E7%BE%8E%E5%8C%96-%E7%BD%91%E9%A1%B5%E4%B8%BB%E9%A2%98%E5%88%87%E6%8D%A2%E7%9A%84%E6%B8%90%E5%8F%98%E5%8A%A8%E7%94%BB/">美化-网页主题切换的渐变动画</a>
          </li>
        
          <li>
            <a href="/2025/09/29/%E5%89%8D%E7%AB%AF/css/css-%E8%A1%A8%E6%A0%BCtd%E4%B8%8B%E9%AB%98%E5%BA%A6%E4%B8%A2%E5%A4%B1%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95/">css-表格td下高度丢失解决办法</a>
          </li>
        
          <li>
            <a href="/2025/09/23/%E5%89%8D%E7%AB%AF/vue/vue-%E5%B0%81%E8%A3%85%E5%87%BD%E6%95%B0%E5%BC%8F%E8%A7%A6%E5%8F%91%E5%8F%B3%E9%94%AE%E8%8F%9C%E5%8D%95/">vue-封装函数式触发右键菜单组件</a>
          </li>
        
          <li>
            <a href="/2025/06/04/%E5%89%8D%E7%AB%AF/UI%E5%BA%93/UI%E5%BA%93-ElTooltip%E5%8F%AA%E5%9C%A8%E6%96%87%E5%AD%97%E8%B6%85%E5%87%BA%E8%8C%83%E5%9B%B4%E6%97%B6%E6%98%BE%E7%A4%BA%E7%9A%84%E8%A7%86%E7%BA%BF%E6%96%B9%E5%BC%8F/">UI库-ElTooltip只在文字超出范围时显示的视线方式</a>
          </li>
        
          <li>
            <a href="/2025/05/29/%E5%89%8D%E7%AB%AF/UI%E5%BA%93/UI%E5%BA%93-%E5%B0%81%E8%A3%85PageTable%E6%80%BB%E8%A7%88/">UI库-封装PageTable总览</a>
          </li>
        
      </ul>
    </div>
  </div>

    
        
        <div class="nexmoe-widget-wrap">
    <div class="nexmoe-widget nexmoe-link">
		<ul>
        
            <li>
                <a href="https://tangyuxian.com/" target="_blank" >
                    <img src="https://cdn.tangyuxian.com/PicGoImages/202304272004917.jpg" alt="糖糖第一可爱"></img>
                    <p style="color: var(--color-primary)">糖糖第一可爱</p>
                </a>
            </li>
        
		</ul>
    </div>
</div>
<style>
.nexmoe-widget-wrap .nexmoe-link ul li a {
    text-align : center;
}
.nexmoe-widget-wrap .nexmoe-link ul li a img {
    max-width : 100%;
}
.nexmoe-widget-wrap .nexmoe-link ul li a p {
    margin: 10px 0;
}
</style>

    
   
    <div class="nexmoe-copyright">
        &copy; 2025 tangyuxian
        Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
        & <a href="https://github.com/tangyuxian/hexo-theme-tangyuxian" target="_blank">Tangyuxian</a>
        <br><a target="_blank" href="https://beian.miit.gov.cn/">辽ICP备2021002341号</a>
<div style="font-size: 12px">
   <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
   本站总访问量  <a id="busuanzi_value_site_pv"></a> 次<br />
   本站访客数<a id="busuanzi_value_site_uv"></a>人次
</div>

    </div>
</div><!-- .nexmoe-drawer --></div><div id="nexmoe-content"><div class="nexmoe-primary"><div class="nexmoe-post">
  <article>
    
        <div class="nexmoe-post-cover">
            <img src="/images/post/java.jpg" alt="java-封装一个向github仓库上传文件的工具" loading="lazy">
            <h1>java-封装一个向github仓库上传文件的工具</h1>
        </div>
        
    
    <div class="nexmoe-post-meta">
    <div class="nexmoe-rainbow">
        <a class="nexmoefont icon-calendar-fill">2022年07月10日</a>
        
            <a class="nexmoefont icon-appstore-fill -link" href="/categories/%E5%90%8E%E7%AB%AF/">后端</a>
        
        
    </div>
    
    
    
    
    
</div>

    <p>在网上没有找到java版的向github仓库上传文件的工具,于是便自己查api封装一个</p>
<span id="more"></span>

<p>为了方便我们可以通过代码执行上传相应文件到github指定仓库,做实时的公共文档或图片存储,github给我们提供一个便利的方式,通过api即可实现文件的上传查询和删除等操作,当时用github存图片时一直没有找到java版本封装好的类库,于是决定自己一边查资料一边巩固自学的java知识,封装一个;</p>
<h2 id="一-申请令牌-github-token"><a href="#一-申请令牌-github-token" class="headerlink" title="一 申请令牌(github token)"></a>一 申请令牌(github token)</h2><p>在<a target="_blank" rel="noopener" href="https://github.com/">github</a>登录成功后,点击<a target="_blank" rel="noopener" href="https://github.com/settings/tokens">此处</a>直接跳转到token申请页面,或通过<strong>用户头像-&gt;Settings-&gt; Developer settings-&gt;Personal access tokens-&gt; Tokens (classic)</strong>:</p>
<p><img onerror="imgOnError(this);" data-fancybox="gallery" src="https://cdn.tangyuxian.com/PicGoImages/202211102009917.png" alt="image-20221110200858095" data-caption="image-20221110200858095" loading="lazy"></p>
<p>点击 <strong>Generate new token</strong>创建新的token,并根据自己的实际情况输入token<strong>描述,时间以及权限</strong>,权限至少勾选<strong>repo</strong>:</p>
<p><img onerror="imgOnError(this);" data-fancybox="gallery" src="https://cdn.tangyuxian.com/PicGoImages/202211102015899.png" alt="image-20221110201503827" data-caption="image-20221110201503827" loading="lazy"></p>
<p>点击最下方的<strong>Generate token</strong>生成token,注意token只显示一次,记得记录保存好:</p>
<p><img onerror="imgOnError(this);" data-fancybox="gallery" src="https://cdn.tangyuxian.com/PicGoImages/202211102018060.png" alt="image-20221110201754927" data-caption="image-20221110201754927" loading="lazy"></p>
<h2 id="二-查阅github的api文档"><a href="#二-查阅github的api文档" class="headerlink" title="二 查阅github的api文档"></a>二 查阅github的api文档</h2><p><a target="_blank" rel="noopener" href="https://docs.github.com/cn/rest/repos/contents">点击此处</a>跳转到官方文档,查阅api的调用方式.简单来说,github采用普通的http方式来实现文件的查询,新增和删除,在这里,我们只针对新增进行封装;</p>
<p>点击<a target="_blank" rel="noopener" href="https://docs.github.com/cn/rest/repos/contents#create-or-update-file-contents">create-or-update-file-contents</a>直接查看文件上传的api.</p>
<p><img onerror="imgOnError(this);" data-fancybox="gallery" src="https://cdn.tangyuxian.com/PicGoImages/202211102034626.png" alt="image-20221110203441698" data-caption="image-20221110203441698" loading="lazy"></p>
<p>我们可以看到一个非常简单的例子,通过<strong>put</strong>请求,将进行好<strong>base64</strong>编码的内容上传到仓库中,</p>
<figure class="shiki"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #e1e4e8">/repos/&quot;+username[用户名]+&quot;/&quot;+depository[仓库名]+&quot;/contents/&quot;+fileName[路径及文件名];</span></span></code></pre></div></div></figure>

<p>既然该有的我们都有了,接下来我们准备封装工具类</p>
<h2 id="三-使用java封装"><a href="#三-使用java封装" class="headerlink" title="三 使用java封装"></a>三 使用java封装</h2><h4 id="1-配置项"><a href="#1-配置项" class="headerlink" title="1 配置项"></a>1 配置项</h4><p>在项目工程的<strong>resources</strong>文件夹下配置<strong>yml</strong>文件:</p>
<figure class="shiki"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #e1e4e8">githubclub:</span></span>
<span class="line"><span style="color: #e1e4e8">  config:</span></span>
<span class="line"><span style="color: #e1e4e8">    username: tangyuxian #用户名</span></span>
<span class="line"><span style="color: #e1e4e8">    token: #token填写在这里</span></span>
<span class="line"><span style="color: #e1e4e8">    depository: blog_image #仓库名</span></span>
<span class="line"><span style="color: #e1e4e8">    message: fromJavaServe #描述</span></span>
<span class="line"><span style="color: #e1e4e8">    domain: https://cdn.jsdelivr.net/gh/tangyuxian/blog_image@latest #cdn加速域名</span></span></code></pre></div></div></figure>

<h4 id="2-封装工具类"><a href="#2-封装工具类" class="headerlink" title="2 封装工具类"></a>2 封装工具类</h4><h6 id="1-HttpUtils-java"><a href="#1-HttpUtils-java" class="headerlink" title="1) HttpUtils.java"></a>1) HttpUtils.java</h6><p>这个工具类用于创建http请求</p>
<figure class="shiki java"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">public</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">class</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">HttpUtils</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">private</span><span style="color: #E1E4E8"> CloseableHttpClient httpClient;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * 与Spring集成初始化HttpClient</span></span>
<span class="line"><span style="color: #6A737D">     * 在Spring启动后会调用init方法</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    @</span><span style="color: #F97583">PostConstruct</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">void</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">init</span><span style="color: #E1E4E8">() {</span></span>
<span class="line"><span style="color: #E1E4E8">        httpClient </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> HttpClients.</span><span style="color: #B392F0">custom</span><span style="color: #E1E4E8">().</span><span style="color: #B392F0">build</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * application-json方式提交</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@param</span><span style="color: #6A737D"> </span><span style="color: #FFAB70">url</span><span style="color: #6A737D"> http路径</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@param</span><span style="color: #6A737D"> </span><span style="color: #FFAB70">json</span><span style="color: #6A737D"> json字符串 {&quot;key&quot;:&quot;value&quot;}</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@return</span><span style="color: #6A737D"> 响应内容字符串</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> String </span><span style="color: #B392F0">postJson</span><span style="color: #E1E4E8">(String </span><span style="color: #FFAB70">url</span><span style="color: #E1E4E8">, String </span><span style="color: #FFAB70">json</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        HttpPost httpPost </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">HttpPost</span><span style="color: #E1E4E8">(url);</span></span>
<span class="line"><span style="color: #E1E4E8">        httpPost.</span><span style="color: #B392F0">setEntity</span><span style="color: #E1E4E8">(</span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">StringEntity</span><span style="color: #E1E4E8">(json, ContentType.APPLICATION_JSON));</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">try</span><span style="color: #E1E4E8">(CloseableHttpResponse response </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> httpClient.</span><span style="color: #B392F0">execute</span><span style="color: #E1E4E8">(httpPost)) {</span></span>
<span class="line"><span style="color: #E1E4E8">            </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> EntityUtils.</span><span style="color: #B392F0">toString</span><span style="color: #E1E4E8">( response.</span><span style="color: #B392F0">getEntity</span><span style="color: #E1E4E8">());</span></span>
<span class="line"><span style="color: #E1E4E8">        } </span><span style="color: #F97583">catch</span><span style="color: #E1E4E8"> (Exception </span><span style="color: #FFAB70">e</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">            </span><span style="color: #F97583">throw</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">RuntimeException</span><span style="color: #E1E4E8">(e);</span></span>
<span class="line"><span style="color: #E1E4E8">        }</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * application/x-www-form-urlencoded 方式提交</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@param</span><span style="color: #6A737D"> </span><span style="color: #FFAB70">url</span><span style="color: #6A737D"> http路径</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@param</span><span style="color: #6A737D"> </span><span style="color: #FFAB70">kvMap</span><span style="color: #6A737D"> key与value组成的map</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@return</span><span style="color: #6A737D"> 响应内容字符串</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> String </span><span style="color: #B392F0">postForm</span><span style="color: #E1E4E8">(String </span><span style="color: #FFAB70">url</span><span style="color: #E1E4E8">, Map&lt;</span><span style="color: #F97583">String</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">String</span><span style="color: #E1E4E8">&gt; </span><span style="color: #FFAB70">kvMap</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        HttpPost httpPost </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">HttpPost</span><span style="color: #E1E4E8">(url);</span></span>
<span class="line"><span style="color: #E1E4E8">        List&lt;</span><span style="color: #F97583">NameValuePair</span><span style="color: #E1E4E8">&gt; nvps </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> ArrayList&lt;&gt;();</span></span>
<span class="line"><span style="color: #E1E4E8">        kvMap.</span><span style="color: #B392F0">forEach</span><span style="color: #E1E4E8">((key, value) </span><span style="color: #F97583">-&gt;</span><span style="color: #E1E4E8"> nvps.</span><span style="color: #B392F0">add</span><span style="color: #E1E4E8">(</span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">BasicNameValuePair</span><span style="color: #E1E4E8">(key, value)));</span></span>
<span class="line"><span style="color: #E1E4E8">        httpPost.</span><span style="color: #B392F0">setEntity</span><span style="color: #E1E4E8">(</span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">UrlEncodedFormEntity</span><span style="color: #E1E4E8">(nvps, Consts.UTF_8));</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">try</span><span style="color: #E1E4E8">(CloseableHttpResponse response </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> httpClient.</span><span style="color: #B392F0">execute</span><span style="color: #E1E4E8">(httpPost)) {</span></span>
<span class="line"><span style="color: #E1E4E8">            </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> EntityUtils.</span><span style="color: #B392F0">toString</span><span style="color: #E1E4E8">(response.</span><span style="color: #B392F0">getEntity</span><span style="color: #E1E4E8">());</span></span>
<span class="line"><span style="color: #E1E4E8">        } </span><span style="color: #F97583">catch</span><span style="color: #E1E4E8"> (Exception </span><span style="color: #FFAB70">e</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">            </span><span style="color: #F97583">throw</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">RuntimeException</span><span style="color: #E1E4E8">(e);</span></span>
<span class="line"><span style="color: #E1E4E8">        }</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * get请求</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@param</span><span style="color: #6A737D"> </span><span style="color: #FFAB70">url</span><span style="color: #6A737D"> http路径 (后可跟参数?p1=aaa&amp;p2=bbb&amp;p3=ccc)</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@return</span><span style="color: #6A737D"> 响应内容字符串</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> String </span><span style="color: #B392F0">getString</span><span style="color: #E1E4E8">(String </span><span style="color: #FFAB70">url</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        HttpGet httpget </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">HttpGet</span><span style="color: #E1E4E8">(url);</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">try</span><span style="color: #E1E4E8">(CloseableHttpResponse response </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> httpClient.</span><span style="color: #B392F0">execute</span><span style="color: #E1E4E8">(httpget)) {</span></span>
<span class="line"><span style="color: #E1E4E8">            </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> EntityUtils.</span><span style="color: #B392F0">toString</span><span style="color: #E1E4E8">(response.</span><span style="color: #B392F0">getEntity</span><span style="color: #E1E4E8">());</span></span>
<span class="line"><span style="color: #E1E4E8">        } </span><span style="color: #F97583">catch</span><span style="color: #E1E4E8"> (Exception </span><span style="color: #FFAB70">e</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">            </span><span style="color: #F97583">throw</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">RuntimeException</span><span style="color: #E1E4E8">(e);</span></span>
<span class="line"><span style="color: #E1E4E8">        }</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * get请求</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@param</span><span style="color: #6A737D"> </span><span style="color: #FFAB70">url</span><span style="color: #6A737D"> http路径 (后可跟参数?p1=aaa&amp;p2=bbb&amp;p3=ccc)</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@return</span><span style="color: #6A737D"> 响应内容</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">byte</span><span style="color: #E1E4E8">[] </span><span style="color: #B392F0">getBytes</span><span style="color: #E1E4E8">(String </span><span style="color: #FFAB70">url</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        HttpGet httpget </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">HttpGet</span><span style="color: #E1E4E8">(url);</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">try</span><span style="color: #E1E4E8">(CloseableHttpResponse response </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> httpClient.</span><span style="color: #B392F0">execute</span><span style="color: #E1E4E8">(httpget)) {</span></span>
<span class="line"><span style="color: #E1E4E8">            </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> EntityUtils.</span><span style="color: #B392F0">toByteArray</span><span style="color: #E1E4E8">(response.</span><span style="color: #B392F0">getEntity</span><span style="color: #E1E4E8">());</span></span>
<span class="line"><span style="color: #E1E4E8">        } </span><span style="color: #F97583">catch</span><span style="color: #E1E4E8"> (Exception </span><span style="color: #FFAB70">e</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">            </span><span style="color: #F97583">throw</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">RuntimeException</span><span style="color: #E1E4E8">(e);</span></span>
<span class="line"><span style="color: #E1E4E8">        }</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * application-json方式提交</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@param</span><span style="color: #6A737D"> </span><span style="color: #FFAB70">url</span><span style="color: #6A737D"> http路径</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@param</span><span style="color: #6A737D"> </span><span style="color: #FFAB70">json</span><span style="color: #6A737D"> json字符串 {&quot;key&quot;:&quot;value&quot;}</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@return</span><span style="color: #6A737D"> 响应内容字符串</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> String </span><span style="color: #B392F0">putJson</span><span style="color: #E1E4E8">(String </span><span style="color: #FFAB70">url</span><span style="color: #E1E4E8">, String </span><span style="color: #FFAB70">json</span><span style="color: #E1E4E8">,Map&lt;</span><span style="color: #F97583">String</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">String</span><span style="color: #E1E4E8">&gt; </span><span style="color: #FFAB70">headerMap</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        HttpPut httpPut </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">HttpPut</span><span style="color: #E1E4E8">(url);</span></span>
<span class="line"><span style="color: #E1E4E8">        headerMap.</span><span style="color: #B392F0">entrySet</span><span style="color: #E1E4E8">().</span><span style="color: #B392F0">forEach</span><span style="color: #E1E4E8">(entry</span><span style="color: #F97583">-&gt;</span><span style="color: #E1E4E8">httpPut.</span><span style="color: #B392F0">addHeader</span><span style="color: #E1E4E8">(entry.</span><span style="color: #B392F0">getKey</span><span style="color: #E1E4E8">(), entry.</span><span style="color: #B392F0">getValue</span><span style="color: #E1E4E8">()));</span></span>
<span class="line"><span style="color: #E1E4E8">        httpPut.</span><span style="color: #B392F0">setEntity</span><span style="color: #E1E4E8">(</span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">StringEntity</span><span style="color: #E1E4E8">(json, ContentType.APPLICATION_JSON));</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">try</span><span style="color: #E1E4E8">(CloseableHttpResponse response </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> httpClient.</span><span style="color: #B392F0">execute</span><span style="color: #E1E4E8">(httpPut)) {</span></span>
<span class="line"><span style="color: #E1E4E8">            </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> EntityUtils.</span><span style="color: #B392F0">toString</span><span style="color: #E1E4E8">( response.</span><span style="color: #B392F0">getEntity</span><span style="color: #E1E4E8">());</span></span>
<span class="line"><span style="color: #E1E4E8">        } </span><span style="color: #F97583">catch</span><span style="color: #E1E4E8"> (Exception </span><span style="color: #FFAB70">e</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">            </span><span style="color: #F97583">throw</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">RuntimeException</span><span style="color: #E1E4E8">(e);</span></span>
<span class="line"><span style="color: #E1E4E8">        }</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * 与Spring集成销毁HttpClient</span></span>
<span class="line"><span style="color: #6A737D">     * 在Spring关闭后会调用destroy方法</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    @</span><span style="color: #F97583">PreDestroy</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">void</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">destroy</span><span style="color: #E1E4E8">() </span><span style="color: #F97583">throws</span><span style="color: #E1E4E8"> Exception {</span></span>
<span class="line"><span style="color: #E1E4E8">        httpClient.</span><span style="color: #B392F0">close</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h6 id="2-GithubClubUtil-java"><a href="#2-GithubClubUtil-java" class="headerlink" title="2) GithubClubUtil.java"></a>2) GithubClubUtil.java</h6><p>这个工具类用来封装文件上传功能</p>
<figure class="shiki java"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #E1E4E8">@</span><span style="color: #F97583">Component</span></span>
<span class="line"><span style="color: #E1E4E8">@</span><span style="color: #F97583">ConfigurationProperties</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">prefix</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;githubclub.config&quot;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #F97583">public</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">class</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">GithubClubUtil</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    @</span><span style="color: #F97583">Autowired</span></span>
<span class="line"><span style="color: #E1E4E8">    HttpUtils httpUtils;</span></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * 用户名</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">private</span><span style="color: #E1E4E8"> String username;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * token</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">private</span><span style="color: #E1E4E8"> String token;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * 仓库名</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">private</span><span style="color: #E1E4E8"> String depository;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * 统一提交信息</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">private</span><span style="color: #E1E4E8"> String message;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * 自定义域名</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">private</span><span style="color: #E1E4E8"> String domain;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">private</span><span style="color: #E1E4E8"> String GITHUBAPI </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;https://api.github.com&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * 文件推送到github</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@param</span><span style="color: #6A737D"> </span><span style="color: #FFAB70">fileName</span><span style="color: #6A737D">  文件名</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@param</span><span style="color: #6A737D"> </span><span style="color: #FFAB70">content</span><span style="color: #6A737D"> json 数据格式 {&quot;message&quot;:&quot;test commit&quot;,&quot;content&quot;:&quot;bXkgbmV3IGZpbGUgY29udGVudHM=&quot;}</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@return</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> HashMap&lt;</span><span style="color: #F97583">String</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">Object</span><span style="color: #E1E4E8">&gt; </span><span style="color: #B392F0">contentFile</span><span style="color: #E1E4E8">(String </span><span style="color: #FFAB70">fileName</span><span style="color: #E1E4E8">, String </span><span style="color: #FFAB70">content</span><span style="color: #E1E4E8">){</span></span>
<span class="line"><span style="color: #E1E4E8">        String url </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> GITHUBAPI </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;/repos/&quot;</span><span style="color: #F97583">+</span><span style="color: #E1E4E8">username</span><span style="color: #F97583">+</span><span style="color: #9ECBFF">&quot;/&quot;</span><span style="color: #F97583">+</span><span style="color: #E1E4E8">depository</span><span style="color: #F97583">+</span><span style="color: #9ECBFF">&quot;/contents/&quot;</span><span style="color: #F97583">+</span><span style="color: #E1E4E8">fileName;</span></span>
<span class="line"><span style="color: #E1E4E8">        HashMap&lt;</span><span style="color: #F97583">String</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">String</span><span style="color: #E1E4E8">&gt; header </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> HashMap&lt;&gt;();</span></span>
<span class="line"><span style="color: #E1E4E8">        header.</span><span style="color: #B392F0">put</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;Authorization&quot;</span><span style="color: #E1E4E8">,</span><span style="color: #9ECBFF">&quot;token &quot;</span><span style="color: #F97583">+</span><span style="color: #E1E4E8">token);</span></span>
<span class="line"><span style="color: #E1E4E8">        header.</span><span style="color: #B392F0">put</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;Accept&quot;</span><span style="color: #E1E4E8">,</span><span style="color: #9ECBFF">&quot;Accept: application/vnd.github.v3+json&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">        String json </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;{</span><span style="color: #79B8FF">\&quot;</span><span style="color: #9ECBFF">message</span><span style="color: #79B8FF">\&quot;</span><span style="color: #9ECBFF">:</span><span style="color: #79B8FF">\&quot;</span><span style="color: #9ECBFF">&quot;</span><span style="color: #F97583">+</span><span style="color: #E1E4E8">message</span><span style="color: #F97583">+</span><span style="color: #9ECBFF">&quot;</span><span style="color: #79B8FF">\&quot;</span><span style="color: #9ECBFF">,</span><span style="color: #79B8FF">\&quot;</span><span style="color: #9ECBFF">content</span><span style="color: #79B8FF">\&quot;</span><span style="color: #9ECBFF">:</span><span style="color: #79B8FF">\&quot;</span><span style="color: #9ECBFF">&quot;</span><span style="color: #F97583">+</span><span style="color: #E1E4E8">content</span><span style="color: #F97583">+</span><span style="color: #9ECBFF">&quot;</span><span style="color: #79B8FF">\&quot;</span><span style="color: #9ECBFF">}&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        String res </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> httpUtils.</span><span style="color: #B392F0">putJson</span><span style="color: #E1E4E8">(url, json, header);</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">filterResultForContentFile</span><span style="color: #E1E4E8">(res,fileName);</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">    /**</span></span>
<span class="line"><span style="color: #6A737D">     * 处理调用接口后返回的值</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@param</span><span style="color: #6A737D"> </span><span style="color: #FFAB70">res</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@param</span><span style="color: #6A737D"> </span><span style="color: #FFAB70">fileName</span></span>
<span class="line"><span style="color: #6A737D">     * </span><span style="color: #F97583">@return</span></span>
<span class="line"><span style="color: #6A737D">     */</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">private</span><span style="color: #E1E4E8"> HashMap&lt;</span><span style="color: #F97583">String</span><span style="color: #E1E4E8">,</span><span style="color: #F97583">Object</span><span style="color: #E1E4E8">&gt; </span><span style="color: #B392F0">filterResultForContentFile</span><span style="color: #E1E4E8">(String </span><span style="color: #FFAB70">res</span><span style="color: #E1E4E8">,String </span><span style="color: #FFAB70">fileName</span><span style="color: #E1E4E8">){</span></span>
<span class="line"><span style="color: #E1E4E8">        Map&lt;</span><span style="color: #F97583">String</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">Object</span><span style="color: #E1E4E8">&gt; map </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> JsonUtil.</span><span style="color: #B392F0">jsonToMap</span><span style="color: #E1E4E8">(res);</span></span>
<span class="line"><span style="color: #E1E4E8">        Map&lt;</span><span style="color: #F97583">String</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">Object</span><span style="color: #E1E4E8">&gt; commit </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (Map</span><span style="color: #F97583">&lt;</span><span style="color: #E1E4E8">String, Object</span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8">) map.</span><span style="color: #B392F0">get</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;commit&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">        HashMap&lt;</span><span style="color: #F97583">String</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">Object</span><span style="color: #E1E4E8">&gt; result </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> HashMap&lt;&gt;();</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">if</span><span style="color: #E1E4E8">(commit.</span><span style="color: #B392F0">get</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;message&quot;</span><span style="color: #E1E4E8">).</span><span style="color: #B392F0">equals</span><span style="color: #E1E4E8">(message)){</span></span>
<span class="line"><span style="color: #E1E4E8">            result.</span><span style="color: #B392F0">put</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;success&quot;</span><span style="color: #E1E4E8">,</span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">            result.</span><span style="color: #B392F0">put</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;data&quot;</span><span style="color: #E1E4E8">,domain</span><span style="color: #F97583">+</span><span style="color: #E1E4E8">fileName);</span></span>
<span class="line"><span style="color: #E1E4E8">        }</span><span style="color: #F97583">else</span><span style="color: #E1E4E8">{</span></span>
<span class="line"><span style="color: #E1E4E8">            result.</span><span style="color: #B392F0">put</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;success&quot;</span><span style="color: #E1E4E8">,</span><span style="color: #79B8FF">false</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">        }</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> result;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> String </span><span style="color: #B392F0">getUsername</span><span style="color: #E1E4E8">() {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> username;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">void</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">setUsername</span><span style="color: #E1E4E8">(String </span><span style="color: #FFAB70">username</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #79B8FF">this</span><span style="color: #E1E4E8">.username </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> username;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> String </span><span style="color: #B392F0">getToken</span><span style="color: #E1E4E8">() {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> token;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">void</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">setToken</span><span style="color: #E1E4E8">(String </span><span style="color: #FFAB70">token</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #79B8FF">this</span><span style="color: #E1E4E8">.token </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> token;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> String </span><span style="color: #B392F0">getDepository</span><span style="color: #E1E4E8">() {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> depository;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">void</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">setDepository</span><span style="color: #E1E4E8">(String </span><span style="color: #FFAB70">depository</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #79B8FF">this</span><span style="color: #E1E4E8">.depository </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> depository;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> String </span><span style="color: #B392F0">getMessage</span><span style="color: #E1E4E8">() {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> message;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">void</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">setMessage</span><span style="color: #E1E4E8">(String </span><span style="color: #FFAB70">message</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #79B8FF">this</span><span style="color: #E1E4E8">.message </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> message;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> String </span><span style="color: #B392F0">getDomain</span><span style="color: #E1E4E8">() {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> domain;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">void</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">setDomain</span><span style="color: #E1E4E8">(String </span><span style="color: #FFAB70">domain</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #79B8FF">this</span><span style="color: #E1E4E8">.domain </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> domain;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h6 id="3-GithubClubConfig-java"><a href="#3-GithubClubConfig-java" class="headerlink" title="3) GithubClubConfig.java"></a>3) GithubClubConfig.java</h6><p>配置信息注入到<strong>Bean</strong>中</p>
<figure class="shiki java"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">public</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">class</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">GithubClubConfig</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    @</span><span style="color: #F97583">Bean</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">public</span><span style="color: #E1E4E8"> GithubClubUtil </span><span style="color: #B392F0">githubClubUtil</span><span style="color: #E1E4E8">(){</span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">GithubClubUtil</span><span style="color: #E1E4E8">();}</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="3-测试工具类"><a href="#3-测试工具类" class="headerlink" title="3 测试工具类"></a>3 测试工具类</h4><h6 id="1-测试下是否可用"><a href="#1-测试下是否可用" class="headerlink" title="1) 测试下是否可用"></a>1) 测试下是否可用</h6><figure class="shiki java"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #E1E4E8">@</span><span style="color: #F97583">GetMapping</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;/uploadFile&quot;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #F97583">public</span><span style="color: #E1E4E8"> R </span><span style="color: #B392F0">uploadFile</span><span style="color: #E1E4E8">(){</span></span>
<span class="line"><span style="color: #E1E4E8">    String fileName </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;test/test3.txt&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    String content </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;bXkgbmV3IGZpbGUgY29udGVudHM=&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    HashMap map </span><span style="color: #F97583">=</span><span style="color: #E1E4E8">  githubClubUtil.</span><span style="color: #B392F0">contentFile</span><span style="color: #E1E4E8">(fileName,content);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">if</span><span style="color: #E1E4E8">((Boolean)map.</span><span style="color: #B392F0">get</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;success&quot;</span><span style="color: #E1E4E8">)){</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> R.</span><span style="color: #B392F0">ok</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span><span style="color: #F97583">else</span><span style="color: #E1E4E8">{</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> R.</span><span style="color: #B392F0">err</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h6 id="2-提供一个文件上传的方法"><a href="#2-提供一个文件上传的方法" class="headerlink" title="2) 提供一个文件上传的方法"></a>2) 提供一个文件上传的方法</h6><p>具体细节根据自己实际情况进一步封装即可</p>
<figure class="shiki java"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #E1E4E8">@</span><span style="color: #F97583">PostMapping</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;/upload&quot;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #F97583">public</span><span style="color: #E1E4E8"> R </span><span style="color: #B392F0">uploadOld</span><span style="color: #E1E4E8">(@</span><span style="color: #F97583">RequestParam</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;file&quot;</span><span style="color: #E1E4E8">) MultipartFile file) {</span></span>
<span class="line"><span style="color: #E1E4E8">    System.out.</span><span style="color: #B392F0">println</span><span style="color: #E1E4E8">(file.</span><span style="color: #B392F0">getOriginalFilename</span><span style="color: #E1E4E8">());</span></span>
<span class="line"><span style="color: #E1E4E8">    System.out.</span><span style="color: #B392F0">println</span><span style="color: #E1E4E8">(file.</span><span style="color: #B392F0">getName</span><span style="color: #E1E4E8">());</span></span>
<span class="line"><span style="color: #E1E4E8">    System.out.</span><span style="color: #B392F0">println</span><span style="color: #E1E4E8">(file.</span><span style="color: #B392F0">getContentType</span><span style="color: #E1E4E8">());</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    String name </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> file.</span><span style="color: #B392F0">getOriginalFilename</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">    String sname </span><span style="color: #F97583">=</span><span style="color: #E1E4E8">name.</span><span style="color: #B392F0">substring</span><span style="color: #E1E4E8">(name.</span><span style="color: #B392F0">lastIndexOf</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;.&quot;</span><span style="color: #E1E4E8">));</span></span>
<span class="line"><span style="color: #E1E4E8">    String fileName </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;/test/&quot;</span><span style="color: #F97583">+</span><span style="color: #9ECBFF">&quot;tyx_&quot;</span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> RandomStringUtils.</span><span style="color: #B392F0">getRandomString</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">10</span><span style="color: #E1E4E8">)</span><span style="color: #F97583">+</span><span style="color: #E1E4E8">sname;</span></span>
<span class="line"><span style="color: #E1E4E8">    Base64 base64Encoder </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">Base64</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">byte</span><span style="color: #E1E4E8">[] imageBytes </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">null</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    String base64EncoderImg</span><span style="color: #F97583">=</span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">try</span><span style="color: #E1E4E8">{</span></span>
<span class="line"><span style="color: #E1E4E8">        imageBytes </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> file.</span><span style="color: #B392F0">getBytes</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">        base64EncoderImg </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> base64Encoder.</span><span style="color: #B392F0">encodeToString</span><span style="color: #E1E4E8">(imageBytes);</span></span>
<span class="line"><span style="color: #E1E4E8">        HashMap map </span><span style="color: #F97583">=</span><span style="color: #E1E4E8">  githubClubUtil.</span><span style="color: #B392F0">contentFile</span><span style="color: #E1E4E8">(fileName,base64EncoderImg);</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">if</span><span style="color: #E1E4E8">((Boolean)map.</span><span style="color: #B392F0">get</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;success&quot;</span><span style="color: #E1E4E8">)){</span></span>
<span class="line"><span style="color: #E1E4E8">            </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> R.</span><span style="color: #B392F0">ok</span><span style="color: #E1E4E8">(map.</span><span style="color: #B392F0">get</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;data&quot;</span><span style="color: #E1E4E8">));</span></span>
<span class="line"><span style="color: #E1E4E8">        }</span><span style="color: #F97583">else</span><span style="color: #E1E4E8">{</span></span>
<span class="line"><span style="color: #E1E4E8">            </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> R.</span><span style="color: #B392F0">err</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">        }</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span><span style="color: #F97583">catch</span><span style="color: #E1E4E8"> (Exception </span><span style="color: #FFAB70">e</span><span style="color: #E1E4E8">){</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">throw</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">RuntimeException</span><span style="color: #E1E4E8">(e);</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<p>大功告成啦!</p>
<p><img onerror="imgOnError(this);" data-fancybox="gallery" src="https://img1.baidu.com/it/u=4140348184,4234695059&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400" alt="小埋" data-caption="小埋" loading="lazy"></p>

    
  </article>

  
      
    <div class="nexmoe-post-copyright">
        <strong>本文作者：</strong>tangyuxian<br>
        
        <strong>本文链接：</strong><a href="https://www.tangyuxian.com/2022/07/10/%E5%90%8E%E7%AB%AF/java/java-%E5%B0%81%E8%A3%85%E4%B8%80%E4%B8%AA%E5%90%91github%E4%BB%93%E5%BA%93%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6%E7%9A%84%E5%B7%A5%E5%85%B7/" title="https:&#x2F;&#x2F;www.tangyuxian.com&#x2F;2022&#x2F;07&#x2F;10&#x2F;%E5%90%8E%E7%AB%AF&#x2F;java&#x2F;java-%E5%B0%81%E8%A3%85%E4%B8%80%E4%B8%AA%E5%90%91github%E4%BB%93%E5%BA%93%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6%E7%9A%84%E5%B7%A5%E5%85%B7&#x2F;" target="_blank" rel="noopener">https:&#x2F;&#x2F;www.tangyuxian.com&#x2F;2022&#x2F;07&#x2F;10&#x2F;%E5%90%8E%E7%AB%AF&#x2F;java&#x2F;java-%E5%B0%81%E8%A3%85%E4%B8%80%E4%B8%AA%E5%90%91github%E4%BB%93%E5%BA%93%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6%E7%9A%84%E5%B7%A5%E5%85%B7&#x2F;</a><br>

        
            <strong>版权声明：</strong>本文采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/cn/deed.zh" target="_blank">CC BY-NC-SA 3.0 CN</a> 协议进行许可

        
    </div>


  
  
  <div class="nexmoe-post-meta nexmoe-rainbow">
   
    
        <a class="nexmoefont icon-tag-fill -none-link" href="/tags/github/" rel="tag">github</a> <a class="nexmoefont icon-tag-fill -none-link" href="/tags/java/" rel="tag">java</a>
    
</div>
  
  
    <script async src="/js/copy-codeblock.js?v=1763992123954"></script>
  

  
      <div class="nexmoe-post-footer">
          <div class="valine"></div>
<script src='https://lib.baomitu.com/valine/1.3.9/Valine.min.js'></script>
<script>
  new Valine({
      el: '.valine',
      appId: 'r5zxC0st0DDjPA9auXzMV7HY-gzGzoHsz',
      appKey: '3bqCsovpyfTPHUzTHovd3V3V'
  })
</script>

      </div>
  
</div></div><div class="nexmoe-post-right">    <div class="nexmoe-fixed">
        <div class="nexmoe-tool">

            

            
            
            <button class="mdui-fab catalog" style="overflow:unset;">
                <i class="nexmoefont icon-i-catalog"></i>
                <div class="nexmoe-toc">
                    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80-%E7%94%B3%E8%AF%B7%E4%BB%A4%E7%89%8C-github-token"><span class="toc-number">1.</span> <span class="toc-text">一 申请令牌(github token)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C-%E6%9F%A5%E9%98%85github%E7%9A%84api%E6%96%87%E6%A1%A3"><span class="toc-number">2.</span> <span class="toc-text">二 查阅github的api文档</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%89-%E4%BD%BF%E7%94%A8java%E5%B0%81%E8%A3%85"><span class="toc-number">3.</span> <span class="toc-text">三 使用java封装</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E9%85%8D%E7%BD%AE%E9%A1%B9"><span class="toc-number">3.0.1.</span> <span class="toc-text">1 配置项</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E5%B0%81%E8%A3%85%E5%B7%A5%E5%85%B7%E7%B1%BB"><span class="toc-number">3.0.2.</span> <span class="toc-text">2 封装工具类</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#1-HttpUtils-java"><span class="toc-number">3.0.2.0.1.</span> <span class="toc-text">1) HttpUtils.java</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#2-GithubClubUtil-java"><span class="toc-number">3.0.2.0.2.</span> <span class="toc-text">2) GithubClubUtil.java</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#3-GithubClubConfig-java"><span class="toc-number">3.0.2.0.3.</span> <span class="toc-text">3) GithubClubConfig.java</span></a></li></ol></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E6%B5%8B%E8%AF%95%E5%B7%A5%E5%85%B7%E7%B1%BB"><span class="toc-number">3.0.3.</span> <span class="toc-text">3 测试工具类</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#1-%E6%B5%8B%E8%AF%95%E4%B8%8B%E6%98%AF%E5%90%A6%E5%8F%AF%E7%94%A8"><span class="toc-number">3.0.3.0.1.</span> <span class="toc-text">1) 测试下是否可用</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#2-%E6%8F%90%E4%BE%9B%E4%B8%80%E4%B8%AA%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0%E7%9A%84%E6%96%B9%E6%B3%95"><span class="toc-number">3.0.3.0.2.</span> <span class="toc-text">2) 提供一个文件上传的方法</span></a></li></ol></li></ol></li></ol></li></ol></li></ol>
                </div>
            </button>
            

            

            <a href="#nexmoe-content" class="backtop toc-link" aria-label="Back To Top" title="top"><button class="mdui-fab mdui-ripple"><i class="nexmoefont icon-caret-top"></i></button></a>
        </div>
    </div>
</div></div><div id="nexmoe-pendant"><div class="nexmoe-drawer mdui-drawer nexmoe-pd" id="drawer">
    
        
            <div class="nexmoe-pd-item">
                <div class="clock">
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="needle" id="hours"></div>
        <div class="needle" id="minutes"></div>
        <div class="needle" id="seconds"></div>
        <div class="clock_logo">

        </div>

    </div>
<script>
        // ----- Variable declaration

        var data = {
                dt: new Date(),
                hours: {
                        el: document.querySelector('#hours'),
                        val: 0 },

                minutes: {
                        el: document.querySelector('#minutes'),
                        val: 0 },

                seconds: {
                        el: document.querySelector('#seconds'),
                        val: 0 },

                renderTime: 1000 };


        // ----- Clock rendering logic

        updateTime = () => {
                let hour = data.dt.getHours();
                let minute = data.dt.getMinutes();
                let second = data.dt.getSeconds();

                data.hours.el.classList.add('moving');
                data.minutes.el.classList.add('moving');
                data.seconds.el.classList.add('moving');

                data.hours.val = hour == 0 && data.hours.val == 59 * 6 * 5 ? 360 : hour * 6 * 5;
                data.minutes.val = minute == 0 && data.minutes.val == 59 * 6 ? 360 : minute * 6;
                data.seconds.val = second == 0 && data.seconds.val == 59 * 6 ? 360 : second * 6;

                data.hours.el.style.transform = `translate(-50%, -75%) rotate(${data.hours.val}deg)`;
                data.minutes.el.style.transform = `translate(-50%, -75%) rotate(${data.minutes.val}deg)`;
                data.seconds.el.style.transform = `translate(-50%, -75%) rotate(${data.seconds.val}deg)`;

                data.dt.setSeconds(second + 1);
        };

        // ----- Clock execution

        setInterval(() => {
                updateTime();
        }, data.renderTime);

        updateTime();

        // ----- Events area

        data.seconds.el.addEventListener('transitionend', () => {
                data.hours.el.classList.remove('moving');
                data.minutes.el.classList.remove('moving');
                data.seconds.el.classList.remove('moving');

                // if (data.hours.val == 360) {
                //   data.hours.el.style.transform = 'translate(-50%, -75%) rotate(0deg)';
                // }

                if (data.minutes.val == 360) {
                        data.minutes.el.style.transform = 'translate(-50%, -75%) rotate(0deg)';
                }

                if (data.seconds.val == 360) {
                        data.seconds.el.style.transform = 'translate(-50%, -75%) rotate(0deg)';
                }
        });

</script>
<style>
    .clock {
        background-color: #ffffff;
        width: 70vw;
        height: 70vw;
        max-width: 70vh;
        max-height: 70vh;
        border: solid 2.8vw var(--color-primary);
        position: relative;
        overflow: hidden;
        border-radius: 50%;
        box-sizing: border-box;
        box-shadow: 0 1.4vw 2.8vw var(--color2);
        zoom:0.2
    }

    .memory {
        position: absolute;
        top: 50%;
        left: 50%;
        transform-origin: center;
    }

    .memory:nth-child(1) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(0deg) translateY(-520%);
    }

    .memory:nth-child(2) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(6deg) translateY(-1461%);
    }

    .memory:nth-child(3) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(12deg) translateY(-1461%);
    }

    .memory:nth-child(4) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(18deg) translateY(-1461%);
    }

    .memory:nth-child(5) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(24deg) translateY(-1461%);
    }

    .memory:nth-child(6) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(30deg) translateY(-520%);
    }

    .memory:nth-child(7) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(36deg) translateY(-1461%);
    }

    .memory:nth-child(8) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(42deg) translateY(-1461%);
    }

    .memory:nth-child(9) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(48deg) translateY(-1461%);
    }

    .memory:nth-child(10) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(54deg) translateY(-1461%);
    }

    .memory:nth-child(11) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(60deg) translateY(-520%);
    }

    .memory:nth-child(12) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(66deg) translateY(-1461%);
    }

    .memory:nth-child(13) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(72deg) translateY(-1461%);
    }

    .memory:nth-child(14) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(78deg) translateY(-1461%);
    }

    .memory:nth-child(15) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(84deg) translateY(-1461%);
    }

    .memory:nth-child(16) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(90deg) translateY(-520%);
    }

    .memory:nth-child(17) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(96deg) translateY(-1461%);
    }

    .memory:nth-child(18) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(102deg) translateY(-1461%);
    }

    .memory:nth-child(19) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(108deg) translateY(-1461%);
    }

    .memory:nth-child(20) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(114deg) translateY(-1461%);
    }

    .memory:nth-child(21) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(120deg) translateY(-520%);
    }

    .memory:nth-child(22) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(126deg) translateY(-1461%);
    }

    .memory:nth-child(23) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(132deg) translateY(-1461%);
    }

    .memory:nth-child(24) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(138deg) translateY(-1461%);
    }

    .memory:nth-child(25) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(144deg) translateY(-1461%);
    }

    .memory:nth-child(26) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(150deg) translateY(-520%);
    }

    .memory:nth-child(27) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(156deg) translateY(-1461%);
    }

    .memory:nth-child(28) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(162deg) translateY(-1461%);
    }

    .memory:nth-child(29) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(168deg) translateY(-1461%);
    }

    .memory:nth-child(30) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(174deg) translateY(-1461%);
    }

    .memory:nth-child(31) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(180deg) translateY(-520%);
    }

    .memory:nth-child(32) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(186deg) translateY(-1461%);
    }

    .memory:nth-child(33) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(192deg) translateY(-1461%);
    }

    .memory:nth-child(34) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(198deg) translateY(-1461%);
    }

    .memory:nth-child(35) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(204deg) translateY(-1461%);
    }

    .memory:nth-child(36) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(210deg) translateY(-520%);
    }

    .memory:nth-child(37) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(216deg) translateY(-1461%);
    }

    .memory:nth-child(38) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(222deg) translateY(-1461%);
    }

    .memory:nth-child(39) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(228deg) translateY(-1461%);
    }

    .memory:nth-child(40) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(234deg) translateY(-1461%);
    }

    .memory:nth-child(41) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(240deg) translateY(-520%);
    }

    .memory:nth-child(42) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(246deg) translateY(-1461%);
    }

    .memory:nth-child(43) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(252deg) translateY(-1461%);
    }

    .memory:nth-child(44) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(258deg) translateY(-1461%);
    }

    .memory:nth-child(45) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(264deg) translateY(-1461%);
    }

    .memory:nth-child(46) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(270deg) translateY(-520%);
    }

    .memory:nth-child(47) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(276deg) translateY(-1461%);
    }

    .memory:nth-child(48) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(282deg) translateY(-1461%);
    }

    .memory:nth-child(49) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(288deg) translateY(-1461%);
    }

    .memory:nth-child(50) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(294deg) translateY(-1461%);
    }

    .memory:nth-child(51) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(300deg) translateY(-520%);
    }

    .memory:nth-child(52) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(306deg) translateY(-1461%);
    }

    .memory:nth-child(53) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(312deg) translateY(-1461%);
    }

    .memory:nth-child(54) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(318deg) translateY(-1461%);
    }

    .memory:nth-child(55) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(324deg) translateY(-1461%);
    }

    .memory:nth-child(56) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(330deg) translateY(-520%);
    }

    .memory:nth-child(57) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(336deg) translateY(-1461%);
    }

    .memory:nth-child(58) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(342deg) translateY(-1461%);
    }

    .memory:nth-child(59) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(348deg) translateY(-1461%);
    }

    .memory:nth-child(60) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(354deg) translateY(-1461%);
    }

    .needle {
        position: absolute;
        top: 50%;
        left: 50%;
        transform-origin: center;
    }

    .needle#hours {
        background-color: #1f1f1f;
        width: 4%;
        height: 30%;
        transform-origin: center 75%;
        transform: translate(-50%, -75%);
    }

    .needle#hours.moving {
        transition: transform 150ms ease-out;
    }

    .needle#hours:after {
        content: '';
        background-color: #1f1f1f;
        width: 4vw;
        height: 4vw;
        max-width: 4vh;
        max-height: 4vh;
        display: block;
        position: absolute;
        top: 75%;
        left: 50%;
        box-sizing: border-box;
        border-radius: 50%;
        transform: translate(-50%, -50%);
    }

    .needle#minutes {
        background-color: #1f1f1f;
        width: 2%;
        height: 45%;
        transform-origin: center 75%;
        transform: translate(-50%, -75%);
    }

    .needle#minutes.moving {
        transition: transform 150ms ease-out;
    }

    .needle#minutes:after {
        content: '';
        background-color: #1f1f1f;
        width: 4vw;
        height: 4vw;
        max-width: 4vh;
        max-height: 4vh;
        display: block;
        position: absolute;
        top: 75%;
        left: 50%;
        box-sizing: border-box;
        border-radius: 50%;
        transform: translate(-50%, -50%);
    }

    .needle#seconds {
        background-color: #cb2f2f;
        width: 1%;
        height: 50%;
        transform-origin: center 75%;
        transform: translate(-50%, -75%);
    }

    .needle#seconds.moving {
        transition: transform 150ms ease-out;
    }

    .needle#seconds:after {
        content: '';
        background-color: #cb2f2f;
        width: 2.5vw;
        height: 2.5vw;
        max-width: 2.5vh;
        max-height: 2.5vh;
        display: block;
        position: absolute;
        top: 75%;
        left: 50%;
        box-sizing: border-box;
        border-radius: 50%;
        transform: translate(-50%, -50%);
    }
    .clock_logo{
        width: 10vw;
        height: 10vw;
        max-width: 10vh;
        max-height: 10vh;
        position: absolute;
        top: 50%;
        left: 50%;
        box-sizing: border-box;
        border-radius: 50%;
        transform: translate(-50%, -50%);
        background-size: 100% 100%;
        background-repeat: no-repeat;
    }
    .clock_logo{
            width: 10vw;
            height: 10vw;
            max-width: 10vh;
            max-height: 10vh;
            position: absolute;
            top: 50%;
            left: 50%;
            box-sizing: border-box;
            border-radius: 50%;
            transform: translate(-50%, -50%);
            background-image: var(--clock-logo);
            background-size: 100% 100%;
            background-repeat: no-repeat;
    }
    @media (min-width: 100vh) {
        .clock {
            border: solid 2.8vh var(--color-primary);
            box-shadow: 0 1.4vh 2.8vh var(--color2);
        }
    }

</style>





            </div>
        
            <div class="nexmoe-pd-item">
                <div class="qweather" >
    <div id="he-plugin-standard">
        <iframe allowtransparency="true" frameborder="0" width="304" height="96" scrolling="no" src="//tianqi.2345.com/plugin/widget/index.htm?s=2&z=1&t=0&v=0&d=2&bd=0&k=000000&f=ff8040&ltf=009944&htf=cc0000&q=1&e=1&a=1&c=54511&w=300&h=96&align=center"></iframe>
    </div>
    <div class="qweather-logo">

    </div>
</div>
<style>
    .qweather{
        position: relative;
        padding-right: 5px;
    }
    .qweather #he-plugin-standard {
        border: 2px solid var(--color-primary);
        box-shadow: 0 1px 0 0 var(--color-primary), 0 1px 2px 0 var(--color-primary);
        border-radius: 8px;
        width: 300px;
        overflow: hidden;
    }
    .qweather-logo{
        position: absolute;
        right: 0;
        top: -15px;
        width: 40px;
        height: 40px;
        background-image: var(--qweather-logo);
        background-size: 100% 100%;
        background-repeat: no-repeat;
    }
</style>

            </div>
        
    
</div>
<style>
    .nexmoe-pd {
        left: auto;
        top: 40px;
        right: 0;
    }
    .nexmoe-pd-item{
       display: flex;
        justify-content: center;
        margin-bottom: 30px;
    }
    #nexmoe-pendant .mdui-drawer{
        width: 305px;
    }
    @media screen and (max-width: 1600px) {
        #nexmoe-pendant {
            display: none
        }
    }
</style>
</div><div id="nexmoe-footer"><!--!--></div><div id="nexmoe-search-space"><div class="search-container"><div class="search-header"><div class="search-input-container"><input class="search-input" type="text" placeholder="搜索" onInput="sinput();"></div><a class="search-close" onclick="sclose();">×</a></div><div class="search-body"></div></div></div><div></div><!-- hexo injector body_end start -->
<script src="https://cdn.jsdelivr.net/npm/hexo-shiki-plugin@latest/lib/codeblock.js"></script>

  <script>
  const CODE_CONFIG = {
    beautify: true,
    highlightCopy: true,
    highlightLang: true,
    highlightHeightLimit: null,
    isHighlightShrink: false,
    copy: {
      success: 'Copy Success',
      error: 'Copy Error',
      noSupport: 'Browser Not Support',
    }
  };
  console.log(
    `%c hexo-shiki-plugin %c v1.0.27 %c https://github.com/nova1751/hexo-shiki-plugin`,
    "color: #fff; background: #5f5f5f",
    "color: #fff; background: #80c8f8",
    ""
  );
  </script>
  <!-- hexo injector body_end end --><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"jsonPath":"/live2dw/assets/xiaomai.model.json"},"display":{"position":"left","width":200,"height":500},"mobile":{"show":false},"react":{"opacity":0.9},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body></html>